home *** CD-ROM | disk | FTP | other *** search
- Path: news.ios.com!usenet
- From: John Leonard <leonardj@tribeca.ios.com>
- Newsgroups: comp.lang.c++
- Subject: Constructors and exceptions
- Date: Thu, 25 Jan 1996 10:58:17 -0500
- Organization: 12th of Nov, Inc
- Message-ID: <3107A899.4A86@tribeca.ios.com>
- NNTP-Posting-Host: ppp-27.ts-9.hck.idt.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b4 (Win95; I)
-
- Let's say that you have a class, we'll call it WindowClass, which, when it is constructed,
- opens a file, allocates memory for the file, reads the file into memory, and then opens a window.
- Let's say furthermore that you are going to create the object with a call to 'new' like this:
-
- WindowClass *aWC = new WindowClass(filename);
-
- Now let's say that during initialization of the object, after it allocates the memory it finds
- that it cannot open the window. At this point I suppose it would be necessary to de-allocate the
- memory that had been allocated and close the file, then throw an exception. Now as far as I can tell
- when you use 'new' like this to allocate and initialize an object two things must happen:
- first, space must be reserved by the 'new' function for the objects data members, then, the
- constructor is called. If this process aborts after the memory has been allocated how can the
- application free it?
- Thanks,
- John Leonard
-